package com.example.seckill.system.tools;

/**
 * 秒杀枚举类
 *
 * @author HL
 */

public enum SeckillEnum {
    /**
     * 秒杀成功
     */
    SUCCESS(0, "秒杀成功！"),
    /**
     * 秒杀失败
     */
    END(1, "秒杀结束！"),
    /**
     * 重复秒杀
     */
    REPEAT_KILL(-1, "重复秒杀！"),
    /**
     * 系统异常
     */
    INNER_ERROR(-2, "系统异常！"),
    /**
     * 数据篡改
     */
    DATA_REWRITE(-3, "数据篡改！");

    /**
     * 编码
     */
    private final int code;
    /**
     * 描述
     */
    private final String msg;

    SeckillEnum(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    /**
     * @param code
     * @return
     * @Description: 根据code获取枚举
     * @CreateTime: 16:24
     * @Version: 1.0
     */
    public static SeckillEnum getseckillEnum(int code) {
        for (SeckillEnum seckillEnum : SeckillEnum.values()) {
            if (seckillEnum.getCode() == code) {
                return seckillEnum;
            }
        }
        return null;
    }
}
